﻿@using LdCms.EF.DbModels
@using LdCms.Common.Utility
@using LdCms.Common.Extension
@model IEnumerable<Ld_Log_TableOperation>
@{
    ViewData["Title"] = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 操作记录 <span class="c-gray en">&gt;</span> 列表
    <a id="btn_refresh" class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container bg-eee" style="min-height:778px;">
    <div class="cl pd-20 bg-fff text-c">
        日期范围：
        <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin" name="datemin" class="input-text Wdate" style="width:120px;" value="@ViewBag.datemin" />
        -
        <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" name="datemax" class="input-text Wdate" style="width:120px;" value="@ViewBag.datemax" />
        <select id="clientId" name="clientId" class="select" style="width:100px; height:31px;vertical-align: middle;">
            <option value="">客户端</option>
            <option value="1" @(ViewBag.ClientID == "1" ? "selected" : "")>Web</option>
            <option value="2" @(ViewBag.ClientID == "2" ? "selected" : "")>M</option>
            <option value="3" @(ViewBag.ClientID == "3" ? "selected" : "")>WX</option>
            <option value="4" @(ViewBag.ClientID == "4" ? "selected" : "")>App</option>
        </select>
        <select id="classId" name="classId" class="select" style="width:100px; height:31px;vertical-align: middle;">
            <option value="">操作类别</option>
            <option value="1" @(ViewBag.ClassID == "1" ? "selected" : "")>Select</option>
            <option value="2" @(ViewBag.ClassID == "2" ? "selected" : "")>Insert</option>
            <option value="3" @(ViewBag.ClassID == "3" ? "selected" : "")>Update</option>
            <option value="4" @(ViewBag.ClassID == "4" ? "selected" : "")>Delete</option>
        </select>
        <input type="text" class="input-text" style="width:350px" placeholder="数据库表名、功能名、操作员帐号、姓名" id="keyword" name="keyword" value="@ViewBag.keyword" />
        <button type="submit" class="btn btn-success radius" id="search" name="search" onclick="$.mainu.search()"><i class="Hui-iconfont">&#xe665;</i> 查找</button>
    </div>
    <div class="cl bg-1 pl-20 pt-10 pb-10 pr-20 mt-10">
        <span class="l">
            <a href="javascript:;" onclick="$.mainu.deleteBatch()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
        </span>
        <span class="r" style="padding-top:5px;">共有数据：<strong>@ViewBag.Count</strong> 条</span>
    </div>
    <div class="pd-20 bg-fff">
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="60">ID</th>
                    <th width="200">表名</th>
                    <th width="80">客户端</th>
                    <th width="80">类别</th>
                    <th width="80">帐号</th>
                    <th width="80">昵称</th>
                    <th width="">备注</th>
                    <th width="120">IP地址</th>
                    <th width="70">结果</th>
                    <th width="120">操作时间</th>
                    <th width="80">操作</th>
                </tr>
            </thead>
            <tbody>
                @if (Model != null)
                {
                    foreach (var m in Model)
                    {
                        <tr class="text-c">
                            <td><input type="checkbox" name="id" value="@m.ID"></td>
                            <td>@m.ID</td>
                            <td class="text-l">@(Html.Raw(Utility.Highlight(m.TableName, ViewBag.keyword)))</td>
                            <td>@m.ClientName</td>
                            <td>@m.ClassName</td>
                            <td>@(Html.Raw(Utility.Highlight(m.Account, ViewBag.keyword)))</td>
                            <td>@(Html.Raw(Utility.Highlight(m.NickName, ViewBag.keyword)))</td>
                            <td class="text-l">@m.Remark</td>
                            <td>@m.IpAdress</td>
                            <td class="td-status">@(m.State.ToBool() ? Html.Raw("<span class='label label-success radius'>成功</span>") : Html.Raw("<span class='label label-defaunt radius'>失败</span>"))</td>
                            <td>@(m.CreateDate.HasValue ? m.CreateDate.Value.ToString("yyyy-MM-dd HH:mm") : "-")</td>
                            <td class="td-manage">
                                <a title="查看" href="javascript:;" onclick="$.mainu.show('查看详情','@Url.Action("Show", new { id = m.ID })')" class="ml-5" style="text-decoration:none">查看</a>
                                <a title="删除" href="javascript:;" onclick="$.mainu.delete(this,'@m.ID')" class="ml-5" style="text-decoration:none">删除</a>
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
        <div style="width:100%; height:35px;"></div>
    </div>
</div>
@*
    --------------
    页面底部JS脚本
    --------------
*@
@section scripts{
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="~/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="~/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="~/admin/lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript" src="~/admin/static/h-ui.admin/js/H-ui.admin.common.js"></script>
    <script type="text/javascript">
            (function ($) {
                $.mainu = {
                    init: function () {
                        $('.table-sort').dataTable({
                            "aaSorting": [[1, "desc"]],//默认第几个排序
                            "bStateSave": true,//状态保存
                            "aoColumnDefs": [
                              { "orderable": false, "aTargets": [0, 11] }// 制定列不参与排序
                            ],
                            "aLengthMenu": [10, 25, 50, 100]
                        });
                    },
                    search: function () {
                        var dateMin = $("input[name='datemin']").val();
                        var dateMax = $("input[name='datemax']").val();
                        var clientId = $("select[name='clientId']").val();
                        var classId = $("select[name='classId']").val();
                        var keyword = $("input[name='keyword']").val();
                        if (keyword == "") {
                            if (dateMin == "" || dateMax == "") {
                                layer.alert('日期范围不能空', { icon: 5 });
                                return;
                            }
                        }
                        var params = {
                            dateMin: dateMin,
                            dateMax: dateMax,
                            clientId: clientId,
                            classId: classId,
                            keyword: keyword
                        };
                        var url = "?" + urlEncodes(params);
                        window.location.href = url;
                    },
                    show: function (title, url) {
                        var index = layer.open({
                            type: 2,
                            title: title,
                            content: url
                        });
                        layer.full(index);
                    },
                    delete: function (obj, id) {
                        layer.confirm('确认要删除吗？', function (index) {
                            $.ajax({
                                type: 'POST',
                                url: '@Url.Action("Delete")',
                                data: { id: id },
                                dataType: 'json',
                                success: function (result) {
                                    var state = result.state;
                                    var message = result.message;
                                    if (state == "success") {
                                        $(obj).parents("tr").remove();
                                        layer.msg('已删除!', { icon: 1, time: 1000 });
                                    } else {
                                        layer.msg(message, { icon: 5, time: 1000 });
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    if (XMLHttpRequest.status != 200) {
                                        layer.alert("系统错误！", { icon: 5 });
                                    }
                                }
                            });
                        });
                    },
                    deleteBatch: function () {
                        layer.confirm('确认要删除吗？', function (index) {
                            var arrId = [];
                            $("input:checkbox[name='id']:checked").each(function () {
                                //alert($(this).val());
                                arrId.push($(this).val());
                            });
                            if (arrId.length == 0) {
                                layer.msg('请选择需要删除日志！', { icon: 5, time: 2000 });
                                return;
                            }
                            $.ajax({
                                type: 'POST',
                                url: '@Url.Action("DeleteBatch")',
                                data: { arrid: arrId },
                                dataType: 'json',
                                success: function (result) {
                                    var state = result.state;          //错误代码
                                    var message = result.message;        //错误说明
                                    if (state == "success") {
                                        window.location.replace(location.href);
                                    } else {
                                        layer.msg(message, { icon: 5, time: 1000 });
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    if (XMLHttpRequest.status != 200) {
                                        layer.alert("系统错误！", { icon: 5 });
                                    }
                                }
                            });
                        });
                    }
                };
                $(function () {
                    $.mainu.init();
                });
            })(jQuery);
    </script>
}

